package com.surekam.core.curl;

import java.security.interfaces.RSAPublicKey;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.bouncycastle.util.Strings;

import com.m3.curly.FormData;
import com.m3.curly.FormData.TextInput;
import com.m3.curly.HTTP;
import com.m3.curly.Request;
import com.m3.curly.Response;
import com.surekam.core.rsa.GZIP;
import com.surekam.core.rsa.Main;
import com.surekam.core.rsa.RSA;

public class CURL {
	public static void main(String[] args) throws Exception {
		Request request = new Request("https://api.baidu.com/sem/common/HolmesLoginService");
		request.setHeader("UUID", "C80AA99AEC09");
		request.setHeader("account_type", "1");
		request.setHeader("Content-Type", "data/gzip;charset=UTF-8");
		request.setUserAgent("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.110 Safari/537.36");
		request.setHeader("Content-Encoding", "gzip");
		
		RSA rsa = new RSA();
		Main m = new Main();
		RSAPublicKey publicKey = rsa.loadPublicKey(null);

		byte[] compress = GZIP.compress(m.toJson());
		byte[] encrypted = rsa.encrypt(publicKey, compress);

		request.setBody(encrypted, "data/gzip ;charset=UTF-8");
//		request.setMultipartFormData(data);

		Response response = HTTP.post(request);

		byte[] body = response.getBody();
		for (byte b : body) {
			System.out.print(b + " ");
		}
		System.out.println();
	}
}
